package org.example.hengshengexam;

public class Calculator {
    // 加法
    public double add(double a, double b) {
        return a + b;
    }
    // 减法
    public double subtract(double a, double b) {
        return a - b;
    }
    // 乘法
    public double multiply(double a, double b) {
        return a * b;
    }
    // 除法
    public double divide(double a, double b) {
        if (b == 0) {
            throw new ArithmeticException("除数不能为0");
        }
        return a / b;
    }
    // 主方法测试
    public static void main(String[] args) {
        Calculator calc = new Calculator();
        double x = 10, y = 5;
        System.out.println(x + " + " + y + " = " + calc.add(x, y));
        System.out.println(x + " - " + y + " = " + calc.subtract(x, y));
        System.out.println(x + " × " + y + " = " + calc.multiply(x, y));
        System.out.println(x + " ÷ " + y + " = " + calc.divide(x, y));
    }
}